plot()
The function plot() explores the distributions and statistics of the dataset. It generates a variety of visualizations and statistics which enables the user to achieve a comprehensive understanding of the column distributions and their relationships. The following describes the functionality of plot() for a given dataframe df.
df
plot(df): plots the distribution of each column and computes dataset statistics
plot(df)
plot(df, x): plots the distribution of column x in various ways, and computes its statistics
plot(df, x)
x
plot(df, x, y): generates plots depicting the relationship between columns x and y
plot(df, x, y)
y
The generated plots are different for numerical and categorical columns. The following table summarizes the output for the different column types.
Output
None
dataset statistics, histogram or bar chart for each column
Numerical
column statistics, histogram, kde plot, qq-normal plot, box plot
Categorical
column statistics, bar chart, pie chart, word cloud, word frequencies
scatter plot, hexbin plot, binned box plot
categorical box plot, multi-line chart
nested bar chart, stacked bar chart, heat map
Next, we demonstrate the functionality of plot().
dataprep.eda supports Pandas and Dask dataframes. Here, we will load the well-known adult dataset into a Pandas dataframe using the load_dataset function.
dataprep.eda
[1]:
from dataprep.datasets import load_dataset import numpy as np df = load_dataset('adult') df = df.replace(" ?", np.NaN)
We start by calling plot(df) which computes dataset-level statistics, a histogram for each numerical column, and a bar chart for each categorical column. The number of bins in the histogram can be specified with the parameter bins, and the number of categories in the bar chart can be specified with the parameter ngroups. If a column contains missing values, the percent of missing values is shown in the title and ignored when generating the plots.
bins
ngroups
[2]:
from dataprep.eda import plot plot(df)
After getting an overview of the dataset, we can thoroughly investigate a column of interest x using plot(df, x). The output is of plot(df, x) is different for numerical and categorical columns.
When x is a numerical column, it computes column statistics, and generates a histogram, kde plot, box plot and qq-normal plot:
[3]:
plot(df, "age")
When x is a categorical column, it computes column statistics, and plots a bar chart, pie chart, word cloud, word frequency and word length:
[4]:
plot(df, "education")
Next, we can explore the relationship between columns x and y using plot(df, x, y). The output depends on the types of the columns.
When x and y are both numerical columns, it generates a scatter plot, hexbin plot and box plot:
[5]:
plot(df, "age", "hours-per-week")
When x and y are both categorical columns, it plots a nested bar chart, stacked bar chart and heat map:
[6]:
plot(df, "education", "marital-status")
When x and y are one each of type numerical and categorical, it generates a box plot per category and a multi-line chart:
[7]:
plot(df, "age", "education") # or plot(df, "education", "age")